package com.example.demo.common;
/* @Author      zouzh
 * @PackageName interceptor-demo
 * @Package     com.example.demo.common
 * @Date        2023/8/25 18:01
 */

import lombok.Data;

@Data
public class ResultJAjax {
    private int code; // 状态码
    private String msg; // 状态码的描述信息
    private  Object data; // 返回数据

    /**
     * 返回成功对象
     * @param data
     * @return
     */
    public static ResultJAjax succ(Object data){
        ResultJAjax resultJAjax = new ResultJAjax();
        resultJAjax.setCode(200);
        resultJAjax.setMsg("");
        resultJAjax.setData(data);
        return resultJAjax;
    }

    public static ResultJAjax succ(Object data, String msg){
        ResultJAjax resultJAjax = new ResultJAjax();
        resultJAjax.setCode(200);
        resultJAjax.setMsg(msg);
        resultJAjax.setData(data);
        return resultJAjax;
    }

    /**
     * 返回失败对象
     * @param code
     * @param msg
     * @return
     */
    public static ResultJAjax fail(int code, String msg){
        ResultJAjax resultJAjax = new ResultJAjax();
        resultJAjax.setCode(code);
        resultJAjax.setMsg(msg);
        resultJAjax.setData(null);
        return resultJAjax;
    }

    public static ResultJAjax fail(int code, String msg, Object data){
        ResultJAjax resultJAjax = new ResultJAjax();
        resultJAjax.setCode(code);
        resultJAjax.setMsg(msg);
        resultJAjax.setData(data);
        return resultJAjax;
    }
}
